$(function () {
  // 密码校验
  const password = document.querySelector('#password')
  // 密码再次校验
  const confirm = document.querySelector('#confirm')
  confirm.addEventListener('change', verifyConfirm)
  function verifyConfirm() {
    if (confirm.value !== password.value) {
      return alert("再次输入密码不一致")
    }

  }

  $('.btn-block').on('click', () => {
    // 获取操作对象
    const mobile = $('#phone').val()
    const password = $('#confirm').val()
    const reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
    if (!reg.test(mobile)) {
      return alert('请输入正确手机号')
    }
    $.ajax({
      method: 'POST',
      url: '/index/reg',
      data: {
        mobile,
        password,
      },
      success(res) {
        // console.log(res)
        if (res.errno !== 0) return alert(res.errmsg)
        alert(res.errmsg)
        localStorage.setItem('token', res.data.token)
        location.href = 'login.html'
      }
    })


  })








})